package cn.hj.springboot_JPA.controller;

import cn.hj.springboot_JPA.config.MyRepository;
import cn.hj.springboot_JPA.pojo.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MyController {
    @Autowired
    private MyRepository myRepository;
    @GetMapping("/person/{id}")
    public String helloPerson(@PathVariable("id") Integer id){
        Person person = myRepository.getOne(id);
        return person.toString();


    }


    @RequestMapping("/user")
    public String insertPerson(Person p){
        myRepository.save(p);
        return p.toString();
    }
    @RequestMapping("/all")
    public String allPerson(){
        List<Person> all = myRepository.findAll();
        return all.toString();
    }
}
